import {Form, message, Modal} from 'antd'
import ProForm, {ProFormDigit, ProFormText} from '@ant-design/pro-form';
import {PutRefundOrder} from "@/services/ant-design-pro/order";

const ImmediateRefundModal = (props) => {
  const {visible, setVisible, id, orderNumber ,price} = props
  const [form] = Form.useForm()
  return (
      <div>
          <Modal
              visible={visible}
              onCancel={ ()=>{ setVisible(false) } }
              title="退款处理"
              onOk={() => {
                  form.validateFields().then(async values=> {
                      if (values.refund_price > price){
                          message.error('不好意思退款金额不能大于实际金额 !!!')
                      } else {
                          await PutRefundOrder(id,{...values})
                          message.success('退款完成!')
                          setTimeout(()=>{
                            setVisible(false)
                          },1000)
                      }
                  })
              }}
          >
              <ProForm
                  form={ form }
                  submitter={ false }
              >
                  <ProFormText  width="md" placeholder={orderNumber} disabled label="退款单号"/>
                  <ProFormDigit
                      label="退款金额"
                      width="sm"
                      min={0.1}
                      name="refund_price"
                      rules={[{required: true,  message: '此为必填'}]}/>
              </ProForm>
          </Modal>
      </div>
  );
};

export default ImmediateRefundModal;
